package com.example.demo.rabbitMQ;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author suliwei
 * @description: 消息生产者
 * @date 2025/3/4 15:08
 */
@Component
public class Producer {

    // @Qualifier("rabbitTemplate")
    @Autowired
    private RabbitTemplate rabbitTemplate;

    public void send() {
        for (int i = 0; i < 5; i++) {
            System.out.println("生产者发送消息，序号为: " + i);
            rabbitTemplate.convertAndSend("test", String.valueOf(i));
        }
    }
}
